package com.ktjiaotu;

import java.lang.reflect.Constructor;

/**
 * @Author: DABINGCHNEGJIAO
 * @CreateTime: 2025-06-03
 * @Description:
 * @Version: 1.0
 */
public class AccessPersonConstructors {
    public static void main(String[] args) {
        try {
            Class clz = Class.forName("com.ktjiaotu.pojo.Person");
            Object o = clz.newInstance();
            System.out.println(o);

            Constructor c1 = clz.getDeclaredConstructor();
            Object o1 = c1.newInstance();
            System.out.println(o1);

            Constructor c2 = clz.getDeclaredConstructor(String.class);
            c2.setAccessible(true);
            Object o2 = c2.newInstance("new person");
            System.out.println(o2);

            Constructor c3 = clz.getDeclaredConstructor(String.class, String.class, String.class);
            c3.setAccessible(true);
            Object o3 = c3.newInstance("new person", "new person", "new person");
            System.out.println(o3);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
